<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/13 0013
 * Time: 上午 10:05
 */

namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use App\Models\Article;
use Illuminate\Http\Request;

class ArticleController extends  Controller
{
    public function get_article(Request $request)
    {
        //0 注册协议
        $type = $request->get('type') ?? 0; 
        //集合
        $ids = [1,2,3];
        //是否post请求
        if ($request->isMethod('post')) {
            //判断type
            if (!in_array($type,array_keys($ids))){
                //返回错误
                return respF(1012);
            }
            //查询
            $list = Article::select('title','content')->where(['id'=>$ids[$type]])->first();
            //没有数据
            if (collect($list)->isEmpty()) {
                //错误
                return respF(1012);
            }
            //成功返回json
            return ['status'=>1,'msg'=>'成功','data'=>$list];
        }

        return view('api/article/index',compact('type'));
    }
}